import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;

/**
 * clase que crea una coleccion de enemigos de tipo Phantom
 * 
 * @author (Octavio y Cesar) 
 * @version (2014.11.28)
 */
public class PhantomGroup extends Actor
{
    private boolean added=false;
    private Phantom[] phantoms=new Phantom[8];
    private Timer time;

    /**
     * contructor de variables para la clase PhantomGroup
     */
    public PhantomGroup()
    {
        time= new Timer();
        GreenfootImage image=getImage();
        image.scale(40,40);
        image.setTransparency(0);
        setImage(image);

        for(int i=0;i<phantoms.length;i++)
            phantoms[i]=new Phantom(i*45,100,100,70,70);
    }

    public void act() 
    {  
        time.increases();    
        if(time.getTime()==5)
        {

            if(added==false)
            {
                addPhantoms();
                added=true;
            }

            movePhantoms();

            if(getY()<getWorld().getHeight()-200)
                setLocation(getX(),getY()+3);

            if(phantoms.length==0)
                getWorld().removeObject(this);

            time.reset();
        }
    }    

    /**
     * agrega los Phantom al mundo
     */
    public void addPhantoms()
    {
        for(int i=0;i<phantoms.length;i++)
            getWorld().addObject(phantoms[i],getX(),getY());

    }
    
    /**
     * mueve a los Phantom
     */
    public void movePhantoms()
    {
        for(int i=0;i<phantoms.length;i++)
            phantoms[i].changeCenter(getX(),getY());  

    }
}
